/**
 * File：   商店请求api.
 */
import {post} from './post'

function uploadImg(base64Data) {
  if (!(base64Data instanceof Array)) {
    base64Data = [base64Data]
  }
  return post('/index.php?act=member_rent&op=upLoadFile', {base64_img: base64Data})
}
// 获取key（公众号微信授权后可获取到）
function getKey() {
  return post('/index.php?act=login&op=getMemberKey', {})
}
// 获取微信jssdk相关参数, url为当前页面地址
function getWxConfig(url) {
  return post('/index.php?act=share&op=share_friends', {url: url})
}
// 根据unionId获取key等信息（app微信登录）
function getKeyByUnionId(unionId) {
  return post('/index.php?act=login&op=getInfoByUnionid', {unionid: unionId})
}
// 验证码登录 checkMobile: {mobile: '', code: '', addtime: ''}
function loginByMessage(mobile, secode, name, password) {
  return post('/index.php?act=login&op=updateMember', {mobile: mobile, secode: secode, member_name: name, password: password})
}
// 密码登录
function loginByPwd(mobile, pwd) {
  return post('/index.php?act=login&op=loginByPassword', {mobile: mobile, password: pwd})
}
// 微信登录
function loginByWeixin(mobile, secode, wxInfo, checkMobile) {
  return post('/index.php?act=login&op=updateMember', {
    mobile: mobile,
    secode: secode,
    checkMobile: checkMobile,
    wxinfo: wxInfo
  })
}
// 获取待付款、待发货、待收货、待评价的数量
function getCountList(type) {
  return post('/index.php/?act=member_order&op=countOrderNum', {order_type: type})
}
// 根据paySn, 获取app的微信支付需要的订单对象
function getWxPayOrder(paySn) {
  return post('/index.php?act=member_payment&op=pay', {pay_sn: paySn, payment_code: 'wxpay'})
}
// 完善资料
function auth({address, area_id, city_id, mobile, name, prov_id, secode, check_mobile}) {
  return post('/index.php?act=login&op=apply', {address, area_id, city_id, mobile, name, prov_id, secode, check_mobile})
}
// 获取是否完善过资料
function getAuth() {
  return post('/index.php?act=login&op=getMemberAllDone', {})
}
// 获取短信验证码
function getMessageCode(mobile) {
  return post('/index.php?act=login&op=sendCheckCode', {mobile: mobile})
}
// app获取短信验证码
function getMessageCode2(mobile) {
  return post('/index.php?act=login&op=sendCheckCode1', {mobile: mobile})
}
// 支付测试接口
function payTest() {
  return post('/index.php?act=member_payment&op=pay_tmp_test')
}
// 获取广告轮播图列表
function getAdvList(storeId) {
  // return post('/index.php?act=index&op=getAdv', {})
  return post('/index.php?act=index&op=getBannerList', {store_id: storeId})
}
// 获取公告列表
function getNoticeList(storeId) {
  return post('/index.php?act=index&op=get_notice_list', {store_id: storeId})
}
// 获取公告详情
function getNoticeDetail(id) {
  return post('/index.php?act=index&op=notice_detail', {notice_id: id})
}
// 获取抢购列表
function getPanicBuyingList(storeId, page, pageSize) {
  return post('/index.php?act=index&op=getGroupBuyInfo', {store_id: storeId, page: page, pageSize: pageSize})
}
// 获取抢购活动的商品列表
function getPanicBuyingGoodsList(id) {
  return post('/index.php?act=index&op=getGroupbuyDetail', {groupbuy_id: id})
}
// 获取新品推荐列表
function getNewGoodsAd(storeId, page, pageSize) {
  return post('/index.php?act=index&op=getNewSeed', {store_id: storeId, page: page, pageSize: pageSize})
}
// 获取热销推荐列表
function getHotGoodsAd(storeId, page, pageSize) {
  return post('/index.php?act=index&op=getHotSeed', {store_id: storeId, page: page, pageSize: pageSize})
}
/**
 * 按照分类获取商品列表
 * gc_id 0 推荐， 1 买花， 2 租花
 * cid: 商品类别
 * price_order   按价格排序 0 升序，1 降序
 * sale_order   按销量排序 0 升序，1 降序
 * store_id 商店id
 * tag_arr 商品标签
 */
function getGoodsByClassify({gc_id, cid = null, page, pageSize, new_order = null, price_order = null, sale_order = null, store_id, tag_arr = null, stc_id = null, keyword = null}) {
  return post('/index.php?act=goods&op=goods_list', {
    gc_id,
    cid,
    page,
    pageSize,
    new_order,
    price_order,
    sale_order,
    store_id,
    tag_arr,
    stc_id,
    keyword
  })
}
// 获取商品详细
function getGoodsCommonInfo(id) {
  return post('/index.php?act=goods&op=get_goods_info', {goods_commonid: id})
}
// 获取商品评价列表
function getGoodsCommentList(id, page, pageSize) {
  return post('/index.php?act=goods&op=getCommentInfoMore', {goods_commonid: id, page: page, pageSize: pageSize})
}
// 获取商品规格列表/根据商品规格获取商品库存等信息(有传规格列表时)
function getGoodsAttributeList(id, attrList) {
  let param = {goods_commonid: id}
  if (attrList) {
    param.attr = attrList
  }
  return post('/index.php?act=goods&op=getAttribute', param)
}
// 加入购物车 cartType: 1买花，2租花
function addGoodsToCart(goodsId, num, cartType) {
  return post('/index.php?act=openshop&op=addCart', {goods_id: goodsId, num: num, cart_type: cartType})
}
// 修改购物车里的商品数量
function modifyGoodsNumToBuy(id, num) {
  return post('/index.php?act=member_cart&op=cart_edit_quantity', {cart_id: id, quantity: num})
}
// 从购物车移出
function delGoodsFromCart(id) {
  return post('/index.php?act=member_cart&op=cart_del', {cart_id: id})
}
// 获取购物车里的商品列表
function getCartList(buyType) {
  return post('/index.php?act=member_cart&op=cart_list', {cart_type: buyType})
}
// 删除收货地址
function delAddress(id) {
  return post('/index.php?act=member_address&op=address_del', {address_id: id})
}
// 获取地址详情
function getAddressInfo(id) {
  return post('/index.php?act=member_address&op=address_info', {address_id: id})
}
// 获取收货地址列表
function getAddressList() {
  return post('/index.php?act=member_address&op=address_list2', {})
}
// 新增收货地址
function addAddress({address, area_id, area_info, city_id, mob_phone, prov_id, tel_phone, true_name, is_default}) {
  return post('/index.php?act=member_address&op=address_add', {
    address,
    area_id,
    area_info,
    city_id,
    mob_phone,
    prov_id,
    tel_phone,
    true_name,
    is_default
  })
}
// 更新收货地址
function updateAddress({address_id, address, area_id, area_info, city_id, mob_phone, prov_id, tel_phone, true_name, is_default}) {
  return post('/index.php?act=member_address&op=address_edit', {
    address_id,
    address,
    area_id,
    area_info,
    city_id,
    mob_phone,
    prov_id,
    tel_phone,
    true_name,
    is_default
  })
}
// 设置默认收货地址
function setDefaultAddress(id) {
  return post('/index.php?act=member_address&op=address_change', {addressid: id})
}
// 获取购买的下单信息
function getBuyInfo(idList, addressId) {
  return post('/index.php?act=member_buy&op=buy_step1', {cart_id: idList, address_id: addressId})
}
// 提交购买的订单
function submitOrder({address_id, cart_id, express_id, ifcart, is_balance, is_integral, order_note, pay_name, self, voucher_id}) {
  return post('/index.php?act=member_buy&op=buy_step2', {
    address_id,
    cart_id,
    express_id,
    ifcart,
    is_balance,
    is_integral,
    order_note,
    pay_name,
    self,
    voucher_id
  })
}
// 获取订单列表
function getOrderList(type, page, pageSize) {
  return post('/index.php?act=member_order&op=order_list', {type: type, page: page, pageSize: pageSize})
}
// 获取积分兑换列表
function getIntegralOrderList(type, page, pageSize) {
  return post('/index.php?act=member_order&op=order_list', {type: type, order_type: '4', page: page, pageSize: pageSize})
}
// 获取订单信息
function getOrderInfo(id) {
  return post('/index.php?act=openshop&op=orderdetail', {order_id: id})
}
// 取消订单
function cancleOrder(id) {
  return post('/index.php?act=member_order&op=updateOverTimeOrder', {order_id: id})
}
// 获取积分列表
function getIntegralList(page, pageSize) {
  return post('/index.php?act=openshop&op=integral_detail', {page: page, pageSize: pageSize})
}
// 获取余额列表
function getBalanceList(page, pageSize) {
  return post('/index.php?act=openshop&op=balance_detail', {page: page, pageSize: pageSize})
}
// 获取省市区
function getArea(type) {
  return post('/index.php?act=member_address&op=returnAreaInfo', {type: type})
}
// 批量添加评论
function addCommentList(commentList, orderId) {
  return post('/index.php?act=openshop&op=evaluate', {goods: commentList, order_id: orderId})
}
// 获取视频列表
function getVideo(page, pageSize) {
  return post('/index.php?act=index&op=videoList', {page: page, pageSize: pageSize})
}
// 获取视频列表
function getVideoDetail(vid) {
  return post('/index.php?act=index&op=getVideoDetail', {id: vid})
}
// 获取首页视频
function homeVideo() {
  return post('/index.php?act=index&op=homePageVideo')
}
// 获取个人信息（需注册后才可取得）
function getMemberInfo() {
  return post('/index.php?act=member&op=getMemberInfo')
}
// 获取个人名字(无需注册)
function getMemberName() {
  return post('/index.php?act=login&op=indexMemberInfo')
}
// 获取消息列表
function getMessageList() {
  return post('')
}
// 获取退款列表
function getRefundMoneyList(page, pageSize) {
  return post('/index.php?act=member_order&op=getRefundInfo1', {page, pageSize})
}
// 获取退货列表
function getRefundGoodsList(page, pageSize) {
  return post('/index.php?act=member_order&op=getRefundInfo2', {page, pageSize})
}
// 获取订单的退货列表
function getRefundGoodsListByOrder(id) {
  return post('/index.php?act=member_order&op=getRefundInfo2', {order_id: id})
}
// 发起退款/退货
function addRefund({goods_num, buyer_message, goods_id, order_id, reason_info, refund_type}) {
  let param = {buyer_message, goods_id, order_id, reason_info, refund_type}
  if (goods_num) { // 退货需要数量
    param.goods_num = goods_num
  }
  return post('/index.php?act=refund&op=addrefund', param)
}
// 退货详情
function getRefundInfo(id) {
  return post('/index.php?act=member_order&op=getRefundDetail', {refund_id: id})
}
// 退货理由列表
function getRefundReasonList() {
  return post('/index.php?act=refund&op=getRefundReason')
}
// 获取物流公司列表
function getExpressList() {
  return post('/index.php?act=refund&op=express')
}
// 添加退货物流信息
function addRefundExpress({refund_id, express_id, express_code}) {
  return post('/index.php?act=refund&op=ship', {refund_id, express_id, express_code})
}
// 获取退货物流信息
function getRefundExpress(id) {
  return post('/index.php?act=refund&op=showinfo', {refund_id: id})
}
// 确认收货
function confirmReceived(id) {
  return post('/index.php?act=openshop&op=confirmOrder', {order_id: id})
}
// 获取订单配送物流信息
function getOrderExpress(id) {
  return post('/index.php?act=member&op=expressDetail', {order_id: id})
}
// 获取微信推广文章列表
function getNewsList(page, pageSize) {
  return post('/index.php?act=member&op=getArticleList', {page: page, pageSize: pageSize})
}
// 获取微信推广文章详细
function getNewsDetail(id) {
  return post('/index.php?act=article_detail&op=article_detail', {id: id})
}
// 获取收藏列表
function getCollectList(page, pageSize) {
  return post('/index.php?act=member&op=getFavsList', {page: page, pageSize: pageSize})
}
// 添加收藏
function addCollect(id) {
  return post('/index.php?act=member&op=addFavorites', {goods_commonid: id})
}
// 删除收藏
function delCollect(id) {
  return post('/index.php?act=member&op=delFavorites', {goods_commonid: id})
}

// 获取erp里的商品库存信息
function getErpStorage(sku) {
  return post('/index.php?act=goods&op=getErpGoodsStorage', {sku: sku})
}
// 修改用户昵称
function editUserName(name) {
  return post('/index.php?act=member&op=editMember', {member_name: name})
}
// 获取邀请人信息
function getInviterInfo() {
  return post('/index.php?act=index&op=getInviterInfo', {})
}
// 获取自提地址列表
function getShopAddressList() {
  return post('/index.php?act=member_buy&op=self_deliveryAddress', {})
}
// 待下单
function addAgentOrder(mobile, remark) {
  return post('/index.php?act=member_order&op=placeOrder', {mobile: mobile, remark: remark})
}
// 获取下级成员列表
function getSubMemberList(page, pageSize) {
  return post('index.php/?act=member&op=getagentlist', {page: page, pageSize: pageSize})
}
// 获取下级成员的订单列表
function getSubOrderList(memberid, page, pageSize, type) {
  return post('/index.php/?act=member&op=order_list', {memberid: memberid, page: page, pageSize: pageSize, type: type})
}
// 获取商店列表
function getStoreList(cityId, page, pageSize, keyword) {
  return post('/index.php?act=store&op=store_list', {city_id: cityId, page: page, pageSize: pageSize, keyword: keyword})
}
// 获取商品标签列表（筛选用）
function getTagList() {
  return post('/index.php?act=goods&op=get_tag_list', {})
}
// 获取租花的下单信息(租花订单确认页)
function getRentInfo(idList) {
  return post('/index.php?act=member_rent&op=buy_step1', {cart_id: idList})
}
/**
 * 提交租花的订单
 * @param address_id 收货地址id
 * @param cart_id 购物车id数组
 * @param express_id 快递id
 * @param ifcart 购物车提交还是直接提交 0 直接购买 1 购物车
 * @param is_balance 是否使用余额 0 不使用 1 使用
 * @param is_integral 是否使用积分 0 不使用 1 使用
 * @param order_note 客户留言
 * @param pay_name 付款方式 'wxpay','balance','abcpay' 农行支付,
 * @param self 是否自提 0 否 1 是
 * @param company 公司名称
 * @param connect 联系方式
 * @param images 场地图片
 * @param industry 行业id
 * @param ins_num 分期期数 处了之前的字段还包括右边这些
 * @param is_installment 是否分期付款 0 否 1 是
 * @param rent_time 租用时长
 * @param scene 场景id
 * @param square 场地面积
 * @param time 期望入驻时间
 * @returns {Promise}
 */
function submitRentOrder({address_id, cart_id, express_id, ifcart, is_balance, is_integral, order_note, pay_name, self, r_company, r_connect, r_images, r_industry, r_ins_num, r_is_installment, r_rent_time, r_scene, r_square, r_time, voucher_id}) {
  return post('/index.php?act=member_rent&op=buy_step2', {
    address_id,
    cart_id,
    express_id,
    ifcart,
    is_balance,
    is_integral,
    order_note,
    pay_name,
    self,
    r_company,
    r_connect,
    r_images,
    r_industry,
    r_ins_num,
    r_is_installment,
    r_rent_time,
    r_scene,
    r_square,
    r_time,
    voucher_id
  })
}
// 获取租花订单详情（租花服务页）
function getRentOrderInfo(id) {
  return post('/index.php?act=member_rent&op=getRentOrderDetail', {order_id: id})
}
// 确认租花服务
function confirmRentService(id) {
  return post('/index.php?act=member_rent&op=memberConfirmService', {s_id: id})
}
// 获取积分商城的轮播图
function getIntagralMallBannerList() {
  return post('/index.php?act=goods&op=getIntegralShopAdvimg', {})
}
// 获取积分商城物品类别列表
function getIntagralMallClassifyList() {
  return post('/index.php?act=goods&op=getIntegralShopClass', {})
}
// 获取用户积分信息
function getIntegralNum() {
  return post('/index.php?act=member&op=getMember_integral', {})
}
// 添加反馈
function addFeedback(content) {
  return post('/index.php?act=member_feedback&op=feedback_add', {feedback: content})
}
// 我的优惠券 storeId: 选填
function getMemberCouponList(type, storeId) {
  return post('/index.php?act=member&op=myVoucher', {store_id: storeId, voucher_type: type})
}
// 获取优惠券详情
function getCouponDetail(id) {
  return post('/index.php?act=goods&op=voucherDetail&tid=' + id, {})
}
// 领取优惠券
function receiveCoupon(couponId) {
  return post('/index.php?act=member&op=getMember_Voucher', {voucher_t_id: couponId})
}
// 商店优惠券列表 type 1 买 2租 空-全部
function getStoreCouponList(storeId, type) {
  return post('/index.php?act=member&op=scVoucherList', {store_id: storeId, voucher_t_type: type})
}
// 根据商店与订单金额过滤后的优惠券列表
function usableCouponList(storeId, orderAmount) {
  return post('/index.php?act=member_buy&op=filtermyVoucher', {store_id: storeId, amount: orderAmount})
}
// 获取积分抵扣金额与使用百分比设置
function getCouponSetting() {
  return post('/index.php?act=goods&op=get_interval_setting', {})
}
// 获取商品分类列表 type: 3 买花 1037 租花 1038买花
function getGoodsClassifyList(type) {
  return post('/index.php?act=goods_class&op=getStoreGoodsClass', {gc_id: type})
}
// 分享朋友圈加积分
function integralAddByShareTimeline(memberId) {
  return post('/index.php?act=garden_task&op=shareFriends', {member_id: memberId})
}
// 分享给朋友加积分
function integralAddByShareFriend(memberId) {
  return post('/index.php?act=garden&op=shareFriend', {member_id: memberId})
}
// 获取分类商品列表（4个商品）
function getClassifyGoods(gc_id, store_id) {
  return post('/index.php?act=goods&op=goods_typelist', {gc_id: gc_id, store_id: store_id})
}
// 获取分类商品数量
function getClassifyGoodsCount(gc_id, store_id) {
  return post('/index.php?act=goods&op=goods_typelist_count', {gc_id: gc_id, store_id: store_id})
}
// 获取店铺信息
function getStoreInfo(store_id) {
  return post('/index.php?act=store&op=store_detail', {store_id: store_id})
}
// 修改密码
function updatePwd(mobile, password, secode) {
  return post('/index.php?act=login&op=updatePassword', {mobile: mobile, password: password, secode: secode})
}
export {
  uploadImg,
  getKey,
  getWxConfig,
  getKeyByUnionId,
  loginByMessage,
  loginByPwd,
  loginByWeixin,
  getCountList,
  getWxPayOrder,
  auth,
  getAuth,
  getMessageCode,
  getMessageCode2,
  payTest,
  getAdvList,
  getNoticeList,
  getNoticeDetail,
  getPanicBuyingList,
  getPanicBuyingGoodsList,
  getNewGoodsAd,
  getHotGoodsAd,
  getGoodsByClassify,
  getGoodsCommonInfo,
  getGoodsCommentList,
  getGoodsAttributeList,
  addGoodsToCart,
  modifyGoodsNumToBuy,
  delGoodsFromCart,
  getCartList,
  delAddress,
  getAddressInfo,
  getAddressList,
  addAddress,
  updateAddress,
  setDefaultAddress,
  getBuyInfo,
  submitOrder,
  getOrderList,
  getIntegralOrderList,
  getOrderInfo,
  getIntegralList,
  getBalanceList,
  cancleOrder,
  addCommentList,
  getArea,
  getVideo,
  getVideoDetail,
  homeVideo,
  getMemberInfo,
  getMemberName,
  getMessageList,
  getRefundMoneyList,
  getRefundGoodsList,
  getRefundGoodsListByOrder,
  addRefund,
  getRefundInfo,
  getRefundReasonList,
  getExpressList,
  addRefundExpress,
  getRefundExpress,
  confirmReceived,
  getOrderExpress,
  getNewsList,
  getNewsDetail,
  getCollectList,
  addCollect,
  delCollect,
  getErpStorage,
  editUserName,
  getInviterInfo,
  getShopAddressList,
  addAgentOrder,
  getSubMemberList,
  getSubOrderList,
  getStoreList,
  getTagList,
  submitRentOrder,
  getRentInfo,
  getRentOrderInfo,
  confirmRentService,
  getIntagralMallBannerList,
  getIntagralMallClassifyList,
  getIntegralNum,
  addFeedback,
  getMemberCouponList,
  getCouponDetail,
  receiveCoupon,
  getStoreCouponList,
  usableCouponList,
  getCouponSetting,
  getGoodsClassifyList,
  integralAddByShareTimeline,
  integralAddByShareFriend,
  getClassifyGoods,
  getClassifyGoodsCount,
  getStoreInfo,
  updatePwd
}